import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect:'/index'
    },
    {
        path: '/login',
        name: 'Login',
        component:()=>import('@/views/Login')
    },
    {
        path: '/home',
        name: 'Home',
        component:()=>import('@/views/Home'),
        children:[
            {
                path :'/index',
                name:'Index',
                component:()=>import('@/components/Index'),
                meta:{
                    keepAlive:true
                }
            },
            {
                path :'/menus',
                name:'MenuList',
                component:()=>import('@/components/system/MenuList'),
                meta:{
                    keepAlive:true
                }
            },
            {
                path :'/permissions',
                name:'PermissionList',
                component:()=>import('@/components/system/PermissionList'),
                meta:{
                    keepAlive:true
                }
            },
            {
                path :'/roles',
                name:'RoleList',
                component:()=>import('@/components/system/RoleList'),
                meta:{
                    keepAlive:true
                }
            },
            {
                path :'/users',
                name:'UserList',
                component:()=>import('@/components/system/UserList'),
                meta:{
                    keepAlive:true
                }
            },
            {
                path :'/onlines',
                name:'OnlineList',
                component:()=>import('@/components/logger/OnlineList'),
                meta:{
                    keepAlive:true
                }
            },
            {
                path :'/operations',
                name:'OperationList',
                component:()=>import('@/components/logger/OperationList'),
                meta:{
                    keepAlive:true
                }
            },
            {
                path :'/versions',
                name:'VersionList',
                component:()=>import('@/components/app/VersionList'),
                meta:{
                    keepAlive:true
                }
            }
        ]
    },
    {
        path: '/404',
        name: 'P404',
        component:()=>import('@/components/P404')
    },
    {
        path: '/500',
        name: 'P500',
        component:()=>import('@/components/P500')
    }
]

const router = new VueRouter({
    routes
})

/**
 * 重写路由的push方法
 */
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(error=> error)
}

export default router
